EC-CUBE 2.11.4
[ class tree: EC-CUBE 2.11.4 ] [ index: EC-CUBE 2.11.4 ] [ all elements ]

Source for file SC_MobileUserAgent.php

Documentation is available at SC_MobileUserAgent.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23. require_once dirname(__FILE__'/../module/Net/UserAgent/Mobile.php';
  24.  
  25. /**
  26.  * 携帯端末の情報を扱うクラス
  27.  *
  28.  * 対象とする携帯端末は $_SERVER から決定する。
  29.  * すべてのメソッドはクラスメソッド。
  30.  */
  31.     /**
  32.      * 携帯端末のキャリアを表す文字列を取得する。
  33.      *
  34.      * 文字列は docomo, ezweb, softbank のいずれか。
  35.      *
  36.      * @return string|false携帯端末のキャリアを表す文字列を返す。
  37.      *                       携帯端末ではない場合は false を返す。
  38.      */
  39.     function getCarrier({
  40.         $objAgent =Net_UserAgent_Mobile::singleton();
  41.         if (Net_UserAgent_Mobile::isError($objAgent)) {
  42.             return false;
  43.         }
  44.  
  45.         switch ($objAgent->getCarrierShortName()) {
  46.         case 'I':
  47.             return 'docomo';
  48.         case 'E':
  49.             return 'ezweb';
  50.         case 'V':
  51.             return 'softbank';
  52.         case 'S':
  53.             return 'softbank';
  54.         default:
  55.             return false;
  56.         }
  57.     }
  58.  
  59.     /**
  60.      * 勝手サイトで利用可能な携帯端末/利用者のIDを取得する。
  61.      *
  62.      * 各キャリアで使用するIDの種類:
  63.      * + docomo   ... UTN
  64.      * + ezweb    ... EZ番号
  65.      * + softbank ... 端末シリアル番号
  66.      *
  67.      * @return string|false取得したIDを返す。取得できなかった場合は false を返す。
  68.      */
  69.     function getId({
  70.         $objAgent =Net_UserAgent_Mobile::singleton();
  71.         if (Net_UserAgent_Mobile::isError($objAgent)) {
  72.             return false;
  73.         elseif ($objAgent->isDoCoMo(|| $objAgent->isVodafone()) {
  74.             $id $objAgent->getSerialNumber();
  75.         elseif ($objAgent->isEZweb()) {
  76.             $id @$_SERVER['HTTP_X_UP_SUBNO'];
  77.         }
  78.         return isset($id$id false;
  79.     }
  80.  
  81.     /**
  82.      * 携帯端末の機種を表す文字列を取得する。
  83.      * 携帯端末ではない場合はユーザーエージェントの名前を取得する。(例: 'Mozilla')
  84.      *
  85.      * @return string 携帯端末のモデルを表す文字列を返す。
  86.      */
  87.     function getModel({
  88.         $objAgent =Net_UserAgent_Mobile::singleton();
  89.         if (Net_UserAgent_Mobile::isError($objAgent)) {
  90.             return 'Unknown';
  91.         elseif ($objAgent->isNonMobile()) {
  92.             return $objAgent->getName();
  93.         else {
  94.             return $objAgent->getModel();
  95.         }
  96.     }
  97.  
  98.     /**
  99.      * EC-CUBE がサポートする携帯キャリアかどうかを判別する。
  100.      *
  101.      * @return boolean サポートしている場合は true、それ以外の場合は false を返す。
  102.      */
  103.     function isMobile({
  104.         $objAgent =Net_UserAgent_Mobile::singleton();
  105.         if (Net_UserAgent_Mobile::isError($objAgent)) {
  106.             return false;
  107.         else {
  108.             return $objAgent->isDoCoMo(|| $objAgent->isEZweb(|| $objAgent->isVodafone();
  109.         }
  110.     }
  111.  
  112.     /**
  113.      * EC-CUBE がサポートする携帯キャリアかどうかを判別する。
  114.      *
  115.      * @return boolean 携帯端末ではない場合は true、それ以外の場合は false を返す。
  116.      */
  117.     function isNonMobile({
  118.         /**
  119.          * ここは、自クラスのメソッドの逆関数なので、
  120.          * EC-CUBE標準規約/リファクタリングガイドラインの
  121.          * SC_Display_Ex::detectDevice()への統一からは除外。
  122.          */
  123.         return !SC_MobileUserAgent_Ex::isMobile();
  124.     }
  125.  
  126.     /**
  127.      * EC-CUBE がサポートする携帯端末かどうかを判別する。
  128.      *
  129.      * @return boolean サポートしている場合は true、それ以外の場合は false を返す。
  130.      */
  131.     function isSupported({
  132.         $objAgent =Net_UserAgent_Mobile::singleton();
  133.  
  134.         // 携帯端末だと認識されたが、User-Agent の形式が未知の場合
  135.         if (Net_UserAgent_Mobile::isError($objAgent)) {
  136.             GC_Utils_Ex::gfPrintLog($objAgent->toString());
  137.             return false;
  138.         }
  139.  
  140.         if ($objAgent->isDoCoMo()) {
  141.             $arrUnsupportedSeries array('501i''502i''209i''210i');
  142.             $arrUnsupportedModels array('SH821i''N821i''P821i ''P651ps''R691i''F671i''SH251i''SH251iS');
  143.             return !in_array($objAgent->getSeries()$arrUnsupportedSeries&& !in_array($objAgent->getModel()$arrUnsupportedModels);
  144.         elseif ($objAgent->isEZweb()) {
  145.             return $objAgent->isWAP2();
  146.         elseif ($objAgent->isVodafone()) {
  147.             return $objAgent->isPacketCompliant();
  148.         else {
  149.             // 携帯端末ではない場合はサポートしていることにする。
  150.             return true;
  151.         }
  152.     }
  153.  
  154. }
  155. ?>

Documentation generated on Fri, 24 Feb 2012 14:02:50 +0900 by Seasoft